<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Detail extends MY_Controller {
	function __construct(){
		parent::__construct();
		if(!$this->uri->segment(3)||!is_numeric($this->uri->segment(3))){
			show_404();
		}
	}
	
	public function index(){
		$dir = $this->uri->segment(2);
		$thiscategory = $this->Cache_model->loadCategoryByDir($dir);
		if(!$thiscategory){show_404();}
		$id = $this->uri->segment(3);
		if(!is_numeric($id)){show_404();}
		$detail = $this->Cache_model->loadDetail($thiscategory,$id);
		if(!$detail){show_404();}
		$this->Data_model->setHits($detail['id'],$thiscategory['model']);
		$this->seo($thiscategory['title']==''?$thiscategory['name']:$thiscategory['title'],
			$thiscategory['keywords']==''?$thiscategory['name']:$thiscategory['keywords'],
			$thiscategory['description']==''?'':$thiscategory['description']);
		$res = array(
				'detail'=>$detail,
				'category'=>$thiscategory
		);
		$tpl = $thiscategory['tpldetail']==''?$thiscategory['model'].'_detail':$thiscategory['tpldetail'];
		$this->view($tpl,$res);
	}
}